//一般直接写在一个js文件中
layui.use(['element','form','layer','laytpl','laydate'],function () {
    var element = layui.element,
            laydate = layui.laydate;
    laydate.render({
        elem: '#endTime' //指定元素
    });
    $(function () {
        var input = $("#print").find("input:radio");
        input.attr("disabled","disabled");
    })
    element.on('tab(demo)', function(data){
            if(data.index == 1 || data.index == 2 || data.index == 3 || data.index == 4 || data.index == 5){
                if (data.index == 1) {
                    $("#xuanfu").hide();
                    $("#xuanfu2").hide();
                    $("#xuanfu1").show();
                    $('#jibingForm').trigger("click");
                }else if (data.index == 2) {
                    $("#xiangmu").text("日常生活活动总分 :");
                    $("#xiangmufj").text("日常生活活动分级 :");
                    $("#xfone").text("总分 100 分");
                    $("#xftwo").text("总分 65-95 分");
                    $("#xfthree").text("总分 45-60 分");
                    $("#xffour").text("总分≤40 分");
                    $("#xuanfu1").hide();
                    $("#xuanfu2").hide();
                    $("#xuanfu").show();
                    $('#richangForm').trigger("click");
                }else if (data.index == 3) {
                    $("#xiangmu").text("精神状态总分 :");
                    $("#xiangmufj").text("精神状态分级 :");
                    $("#xfone").text("总分为 0 分");
                    $("#xftwo").text("总分为 1 分");
                    $("#xfthree").text("总分 2-3 分");
                    $("#xffour").text("总分 4-6 分");
                    $("#xuanfu1").hide();
                    $("#xuanfu2").hide();
                    $("#xuanfu").show();
                    $('#jingshenForm').trigger("click");
                }else if (data.index == 4){
                    $("#xuanfu").hide();
                    $("#xuanfu1").hide();
                    $("#xuanfu2").show();
                    $('#ganzhiForm').trigger("click");
                }else if (data.index == 5){
                    $("#xiangmu").text("社会参与总分 :");
                    $("#xiangmufj").text("社会参与分级 :");
                    $("#xfone").text("总分 0-2 分");
                    $("#xftwo").text("总分 3-7 分");
                    $("#xfthree").text("总分 8-13 分");
                    $("#xffour").text("总分 14-20 分");
                    $("#xuanfu1").hide();
                    $("#xuanfu2").hide();
                    $("#xuanfu").show();
                    $('#shehuiForm').trigger("click");
                }
            }else{
                $("#xuanfu1").hide();
                $("#xuanfu").hide();
                $("#xuanfu2").hide();
            }
    });
    //疾病意外选项监听
    $("#jibingForm").on('click',function () {
        var chidai=$("input[name='stupid']:checked").val();
        var jingshen=$("input[name='spirit']:checked").val();
        var diedao=$("input[name='fall']:checked").val();
        var zoushi=$("input[name='lost']:checked").val();
        var yeshi=$("input[name='foraging']:checked").val();
        var zisha=$("input[name='suicide']:checked").val();
        if (chidai>0 || jingshen>0 && diedao<2 && zoushi<2 && yeshi<2 && zisha<2 ){
            $("#score1").text("有认知障碍/痴呆、精神疾病者，在原有能力级别上提高一个等级；");
        }else  if (diedao>1 || zoushi>1 || yeshi>1 || zisha>1 ){
            $("#score1").text("近 30 天内发生过 2 次及以上跌倒、噎食、自杀、走失者，在原有能力级别上提高一个等级；");
        }else{
            $("#score1").text("无");
        }
    })
    //日常生活评估选项监听
    $("#richangForm").on('click',function () {
        var jinshi=$("input[name='jinshi']:checked").val()==undefined?0:$("input[name='jinshi']:checked").val();
        var xizao=$("input[name='xizao']:checked").val()==undefined?0:$("input[name='xizao']:checked").val();
        var xiushi=$("input[name='xiushi']:checked").val()==undefined?0:$("input[name='xiushi']:checked").val();
        var chuanyi=$("input[name='chuanyi']:checked").val()==undefined?0:$("input[name='chuanyi']:checked").val();
        var dabian=$("input[name='dabian']:checked").val()==undefined?0:$("input[name='dabian']:checked").val();
        var xiaobian=$("input[name='xiaobian']:checked").val()==undefined?0:$("input[name='xiaobian']:checked").val();
        var ruce=$("input[name='ruce']:checked").val()==undefined?0:$("input[name='ruce']:checked").val();
        var zychuangyi=$("input[name='zychuangyi']:checked").val()==undefined?0:$("input[name='zychuangyi']:checked").val();
        var pdfoot=$("input[name='pdfoot']:checked").val()==undefined?0:$("input[name='pdfoot']:checked").val();
        var sxfloor=$("input[name='sxfloor']:checked").val()==undefined?0:$("input[name='sxfloor']:checked").val();
        var score=Number(jinshi)+Number(xizao)+Number(xiushi)+Number(chuanyi)+Number(dabian)+Number(xiaobian)+Number(ruce)+Number(zychuangyi)+Number(pdfoot)+Number(sxfloor);
        $("#score").text(score);
        if (score>95){
            $("#pjresult").text("能力完好");
        }else if (score>=65 && score<= 95){
            $("#pjresult").text("轻度受损");
        } else if (score>=45 && score<= 60){
            $("#pjresult").text("中度受损");
        }else if (score<= 40){
            $("#pjresult").text("重度受损");
        }
    })
    //精神评估选项监听
    $("#jingshenForm").on('click',function () {
        var renzhi=$("input[name='renzhi']:checked").val()==undefined?0:$("input[name='renzhi']:checked").val();
        var kill=$("input[name='kill']:checked").val()==undefined?0:$("input[name='kill']:checked").val();
        var yiyu=$("input[name='yiyu']:checked").val()==undefined?0:$("input[name='yiyu']:checked").val();
        var score=Number(renzhi)+Number(kill)+Number(yiyu);
        $("#score").text(score);
        if (score==0){
            $("#pjresult").text("能力完好");
        }else if (score== 1){
            $("#pjresult").text("轻度受损");
        } else if (score==1 || score== 3){
            $("#pjresult").text("中度受损");
        }else if (score>3){
            $("#pjresult").text("重度受损");
        }
    })
    //感知觉与沟通评估选项监听
    $("#ganzhiForm").on('click',function () {
        var yishi=$("input[name='yishi']:checked").val()==undefined?0:$("input[name='yishi']:checked").val();
        var shili=$("input[name='shili']:checked").val()==undefined?0:$("input[name='shili']:checked").val();
        var tingli=$("input[name='tingli']:checked").val()==undefined?0:$("input[name='tingli']:checked").val();
        var gotong=$("input[name='gotong']:checked").val()==undefined?0:$("input[name='gotong']:checked").val();

        if (yishi==0 && (shili <=1 || tingli <=1 ) &&  gotong==0){
            $("#score2").text("0");
            $("#pjresult2").text("能力完好");
        }else if (yishi==0 &&(shili==2 || tingli==2 || gotong==1)){
            $("#score2").text("1");
            $("#pjresult2").text("轻度受损");
        } else if ((yishi==0  && (shili==3 || tingli==3 || gotong==2)) || (yishi==1 && (shili<=3 || tingli<=3) && gotong<=2 )){
            $("#score2").text("2");
            $("#pjresult2").text("中度受损");
        }else if ((yishi<=1 && (shili==4 || tingli==4 || gotong==3))|| yishi>=2 ){
            $("#score2").text("3");
            $("#pjresult2").text("重度受损");
        }
    })
    //社会参与评估选项监听
    $("#shehuiForm").on('click',function () {
        var shenghuo=$("input[name='shenghuo']:checked").val()==undefined?0:$("input[name='shenghuo']:checked").val();
        var job=$("input[name='job']:checked").val()==undefined?0:$("input[name='job']:checked").val();
        var skdingxiang=$("input[name='skdingxiang']:checked").val()==undefined?0:$("input[name='skdingxiang']:checked").val();
        var rendingxiang=$("input[name='rendingxiang']:checked").val()==undefined?0:$("input[name='rendingxiang']:checked").val();
        var shehuinl=$("input[name='shehuinl']:checked").val()==undefined?0:$("input[name='shehuinl']:checked").val();
        var score=Number(shenghuo)+Number(job)+Number(skdingxiang)+Number(rendingxiang)+Number(shehuinl);
        $("#score").text(score);
        if (score<=2){
            $("#pjresult").text("能力完好");
        }else if (score>= 3 && score<= 7){
            $("#pjresult").text("轻度受损");
        } else if (score>=8 && score<=13){
            $("#pjresult").text("中度受损");
        }else if (score>13){
            $("#pjresult").text("重度受损");
        }
    })
    $("#dy").on('click',function(){
        var $print = $("#print");
        $print.find(".hulve").hide();
        $print.jqprint();
        $print.find(".hulve").show();
    });
});
